home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / vsrc.tar / voyager7_src / dmptomem.c < prev    next >
C/C++ Source or Header  |  1991-02-27  |  2KB  |  127 lines

  1. /*
  2. // Abstract:
  3. //    DMPTOMEM
  4. //
  5. //    Converts a memory scanner dump (DMP) to Voyager format (MEM).
  6. //
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #define DEBUG 0
  14. #define MAX_LINE 25
  15.  
  16. #define vgr__openin \
  17. "%%VOYAGER-E-OPENIN, error opening %s as input\n"
  18.  
  19. #define vgr__openout \
  20. "%%VOYAGER-E-OPENOUT, error opening %s as output\n"
  21.  
  22. #define vgr__usage \
  23. "%%VOYAGER-I-USAGE, usage is: DMPTOMEM input[.DMP] [output[.MEM]]\n"
  24.  
  25.     FILE *ifile;
  26.     FILE *ofile;
  27.     char drive[_MAX_DRIVE];
  28.     char subdirectory[_MAX_DIR];
  29.     char filename[_MAX_FNAME];
  30.     char extension[_MAX_EXT];
  31.     char ipath[_MAX_PATH];
  32.     char opath[_MAX_PATH];
  33.     char buf[MAX_LINE];
  34.  
  35. main(int argc, char *argv[])
  36. {
  37.     /*
  38.     // Check for correct number of parameters.
  39.     */
  40.  
  41.     if (argc < 2 || argc > 3) {
  42.         printf(vgr__usage);
  43.         exit(-1);
  44.     }
  45.  
  46.     /*
  47.     // Get the path for the input file and supply defaults.
  48.     */
  49.  
  50.     _splitpath(argv[1],drive,subdirectory,filename,extension);
  51.  
  52. #if DEBUG
  53.     printf("drive:        %s\n", drive);
  54.     printf("subdirectory: %s\n", subdirectory);
  55.     printf("filename:     %s\n", filename);
  56.     printf("extension:    %s\n", extension);
  57. #endif
  58.  
  59.     if (strcmp(extension,"") == 0) strcpy(extension,".DMP");
  60.     _makepath(ipath,drive,subdirectory,filename,extension);
  61.  
  62.     /*
  63.     // Get the path for the output file and supply defaults.
  64.     */
  65.  
  66.     if (argc == 3) {
  67.         _splitpath(argv[2],drive,subdirectory,filename,extension);
  68.         if (strcmp(extension,"") == 0) strcpy(extension,".MEM");
  69.         _makepath(opath,drive,subdirectory,filename,extension);
  70.     } else {
  71.         strcpy(extension,".MEM");
  72.         _makepath(opath,NULL,NULL,filename,extension);
  73.     }
  74.  
  75.     /*
  76.     // Convert to uppercase.
  77.     */
  78.  
  79.     strupr(ipath);
  80.     strupr(opath);
  81.  
  82. #if DEBUG
  83.     printf("Input file:   %s\n",ipath);
  84.     printf("Output file:  %s\n",opath);
  85. #endif
  86.     /*
  87.     // Open the input file.
  88.     */
  89.  
  90.     ifile = fopen(ipath, "rt");
  91.  
  92.     if (ifile == NULL) {
  93.         fprintf(stderr, vgr__openin, ipath);
  94.         exit(-1);
  95.     }
  96.  
  97.     /*
  98.     // Open the output file.
  99.     */
  100.  
  101.     ofile = fopen(opath, "wt");
  102.  
  103.     if (ofile == NULL) {
  104.         fprintf(stderr, vgr__openin, opath);
  105.         exit(-1);
  106.     }
  107.  
  108.     /*
  109.     // Read from the input and write to the output, reformatting as
  110.     // as we go.
  111.     */
  112.  
  113.     while (!feof(ifile)) {
  114.         if (fgets(buf,MAX_LINE,ifile)) {
  115.             buf[22] = '\0';
  116.             fputs(buf+6, ofile);
  117.         }
  118.     }
  119.  
  120.     /*
  121.     // Close the files.
  122.     */
  123.  
  124.     fclose(ifile);
  125.     fclose(ofile);
  126. }
  127.